import { _decorator, Component, Camera, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('CameraManager')
export class CameraManager extends Component {
    start() {
        let camera1 = this.node.getChildByName('CameraBody').getComponent(Camera);
    }

    update(deltaTime: number) {
        // 调用函数切换摄像头
        this.switchCamera('camera1');
    }


    switchCamera(cameraName) {
        let camera1 = this.node.getChildByName('CameraBody').getComponent(Camera);
        let camera2 = this.node.getChildByName('CameraGunTower').getComponent(Camera);
        if (cameraName === 'CameraBody') {
            camera1.enabled = true;
            camera2.enabled = false;
        } else if (cameraName === 'CameraGunTower') {
            camera1.enabled = false;
            camera2.enabled = true;
        }
    }



}

// 参考链接：https://blog.csdn.net/qq_41162289/article/details/141642536
//【Cocos Creator深度探索】打造极致游戏体验：Camera的妙用与实战技巧